/**
 * 
 */
package org.andersonb.prototypes.jpa.entity;

import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

/**
 * @author abernardo
 * 
 */
// @Service("loginService")
public class LoginServiceImpl implements LoginService {

	// @Autowired
	private GenericDAO<Login> loginDAO = new GenericJpaDAOImpl<Login>();

	public LoginServiceImpl() {
	}

	/**
	 * {@inheritDoc}
	 */
	// @Transactional(readOnly=true)
	@Override
	public Login login(String username, String password) {
		EntityManager em = loginDAO.getEntityManager();

		TypedQuery<Login> q = em
				.createQuery(
						"select l from Login l where l.login = :login and l.password = :password",
						Login.class);
		q.setParameter("login", username);
		q.setParameter("password", password);

		return q.getSingleResult();
	}

}
